# -*- coding: utf-8 -*-
import os

from multiprocessing import Process

from tornado.ioloop import IOLoop

from program_top.utilities.csv_and_json_serialisation import clean_load_json, temperarily_save_a_local_json
from program_top.utilities.environment_and_platform import get_current_environment_pack

def defaul_run(self):
	'''默认进程函数'''
	if hasattr(self, 'config_file'):
		self.__working_instance=self.__working_type(self.config_file)
	else:
		self.__working_instance=self.__working_type()
		pass
	IOLoop.current().start()
	pass


class my_engine(Process):
	'''
	进程引擎，接受socket监听作为事件循环，发出请求的时候发起连接
	初始化确定本进程的执行参数，包括平台，python版本
	'''
		
	def __init__(self,working_type=None,config_file=None):
		super(my_engine, self).__init__()
		
		environment_pack=get_current_environment_pack()
		if working_type.__class__.__name__=='function':#加载函数模式
			function_name=working_type.__name__
			self.run=working_type
			self.start()
				
		else:#加载类模式
			if config_file:
				self.config_file=config_file
			
			if working_type:#加载类模式
				self.__working_type=working_type
				self.__working_instance=None
			self.run=defaul_run
			self.start()
			pass
		pass
	pass